
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region MemberClass Model -(by fangyifeng at 2007-09-14 12:24:10)

	/// <summary>
	/// MemberClass object'MemberClass'.
	/// </summary>
	[Serializable]
	public class MemberClass : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected string _name;
		protected string _description;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public MemberClass() { }

		public MemberClass( string name, string description )
		{
			this._name = name;
			this._description = description;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual string Name
		{
			get { return _name; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Name", value, value.ToString());
				_name = value;
			}
		}

		public virtual string Description
		{
			get { return _description; }
			set
			{
				if ( value != null && value.Length > 80)
					throw new ArgumentOutOfRangeException("Invalid value for Description", value, value.ToString());
				_description = value;
			}
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is MemberClass))
				throw new InvalidCastException("This object is not of type MemberClass");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((MemberClass)obj).Id);
					break;
				case "Name":
					relativeValue = this.Name.CompareTo(((MemberClass)obj).Name);
					break;
				case "Description":
					relativeValue = (this.Description != null) ? this.Description.CompareTo(((MemberClass)obj).Description) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (MemberClass.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
